package com.coolingme.algo_01_list.lrucache;

/**
 * 缓存淘汰算法测试
 *
 * @author wangyue
 * @date 2020/11/9 10:00
 */
public class LRUTest {

    public static void main(String[] args) {
        // 0[头结点] => -1(0)[尾节点]
        LRUCache lruCache = new LRUCache(3);

        // 0[头结点] => 1(0)[一帆风顺] => -1(1)[尾节点]
        lruCache.put(1, "一帆风顺");
        // 0[头结点] => 1(0)[一帆风顺] => 2(1)[二龙腾飞] => -1(2)[尾节点]
        lruCache.put(2, "二龙腾飞");

        // 0[头结点] => 2(0)[二龙腾飞] => 1(2)[一帆风顺] => -1(1)[尾节点]
        // 一帆风顺
        System.out.println(lruCache.get(1));

        // 0[头结点] => 2(0)[二龙腾飞] => 1(2)[一帆风顺] => 3(1)[三阳开泰] => -1(3)[尾节点]
        lruCache.put(3, "三阳开泰");

        // 0[头结点] => 1(0)[一帆风顺] => 3(1)[三阳开泰] => 2(3)[二龙腾飞] => -1(2)[尾节点]
        lruCache.put(2, "二龙戏珠");

        // 0[头结点] => 3(0)[三阳开泰] => 2(3)[二龙戏珠] => 4(2)[四季平安] => -1(4)[尾节点]
        lruCache.put(4, "四季平安");

        // null
        System.out.println(lruCache.get(5));

        // 0[头结点] => 2(0)[二龙戏珠] => 4(2)[四季平安] => 3(4)[三阳开泰] => -1(3)[尾节点]
        // 三阳开泰
        System.out.println(lruCache.get(3));
    }

}
